package com.funtl.framework.web.purview.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;

import com.funtl.framework.java.ssh.abstracts.AbstractAction;
import com.funtl.framework.java.util.common.CommonDate;
import com.funtl.framework.web.entity.Admin;
import com.funtl.framework.web.entity.PurviewColumn;
import com.funtl.framework.web.purview.service.IPurviewColumnService;

/**
 * 权限分栏
 * @author WMLI
 * Create on 2013-5-14
 */
@Scope("prototype")
public class PurviewColumnAction extends AbstractAction {
	private static final long serialVersionUID = -3988843724394372144L;
	private JSONObject result;
	private Map<String, Object> request;
	private Map<String, Object> session;
	
	private PurviewColumn purviewColumn;
	private IPurviewColumnService purviewColumnService;
	
	//page
	
	public String column_manager() throws Exception {
		return SUCCESS;
	}
	
	// common action

	public String get() throws Exception {
		return null;
	}

	public String query() throws Exception {
		List<PurviewColumn> list = purviewColumnService.getList(new PurviewColumn());
		jsonData.put("rows", list);
		result = JSONObject.fromObject(jsonData);
		return SUCCESS;
	}

	public String insert() throws Exception {
		Admin admin = (Admin) session.get("admin");
		purviewColumn.setCreateDate(CommonDate.getDateTime());
		purviewColumn.setCreateId(admin.getId());
		purviewColumn.setCreateName(admin.getUserName());
		purviewColumnService.insert(purviewColumn);
		result = JSONObject.fromObject(jsonData);
		return SUCCESS;
	}

	public String delete() throws Exception {
		purviewColumnService.delete(purviewColumn);
		result = JSONObject.fromObject(jsonData);
		return SUCCESS;
	}

	public String update() throws Exception {
		Admin admin = (Admin) session.get("admin");
		purviewColumn.setUpdateDate(CommonDate.getDateTime());
		purviewColumn.setUpdateId(admin.getId());
		purviewColumn.setUpdateName(admin.getUserName());
		purviewColumnService.update(purviewColumn);
		result = JSONObject.fromObject(jsonData);
		return SUCCESS;
	}
	
	// getter setter

	public JSONObject getResult() {
		return result;
	}

	public void setResult(JSONObject result) {
		this.result = result;
	}

	public Map<String, Object> getRequest() {
		return request;
	}

	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public PurviewColumn getPurviewColumn() {
		return purviewColumn;
	}

	public void setPurviewColumn(PurviewColumn purviewColumn) {
		this.purviewColumn = purviewColumn;
	}

	public IPurviewColumnService getPurviewColumnService() {
		return purviewColumnService;
	}

	@Resource
	public void setPurviewColumnService(IPurviewColumnService purviewColumnService) {
		this.purviewColumnService = purviewColumnService;
	}
	
}
